<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>忘记 修改 密码</title>
        <link rel="stylesheet" th:href="@{/layui/css/font.css}">
        <link rel="stylesheet" th:href="@{/layui/css/xadmin.css}">
        <link rel="stylesheet" th:href="@{/layui/css/login.css}">
        <script charset="utf-8" th:src="@{/layui/lib/layui/layui.js}"></script>
        <script th:src="@{/layui/js/xadmin.js}" type="text/javascript"></script>
        <style>
            body,html {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
            }
            .login input[type=text], .login input[type=file], .login input[type=password], .login input[type=email], select {
                display: inline-block;
            }
        </style>
    </head>
    <body class="login-bg">
        <div style="display: none">
            <label>
                <input id="universityId" th:value="${university.id}">
            </label>
        </div>
        <div class="login layui-anim layui-anim-up">
            <div class="message">Reset Password</div>
            <div id="darkbannerwrap"></div>
            <form class="layui-form" >
                <hr class="hr20">
                <label for="password">密&emsp;&emsp;码&emsp;</label>
                <input class="layui-input" id="password" name="password" required style="width: 250px"
                       type="password">
                <hr class="hr15">
                <label for="re_password">确认密码&emsp;</label>
                <input class="layui-input" id="re_password" lay-verify="re_password" name="re_password" required style="width: 250px"
                       type="password">
                <hr class="hr15">
                <input lay-filter="resetPassword" lay-submit style="width:100%;" type="submit" value="提交">
                <hr class="hr20">
            </form>
        </div>
        <script>
            layui.use('form', function(){
                const $ = layui.jquery;
                const form = layui.form;
                const universityId = $('#universityId').val();
                form.verify({
                    re_password : function () {
                        if ($('#password').val() !== $('#re_password').val()) {
                            return "两次密码输入不一致!";
                        }
                    }
                })
                //监听提交
                form.on('submit(resetPassword)', function(data){
                    $.ajax({
                        url : "/university_reset_password?id=" + universityId,
                        method : 'post',
                        data : data.field,
                        dataType : 'JSON',
                        success:function(res){
                            if(res.code === 0){
                                //弹出提示，并在1秒后进行跳转
                                layer.msg("修改成功",{icon: 1, time: 1000},function(){
                                    xadmin.close();
                                    xadmin.father_reload();
                                    return false;
                                });
                            }else{
                                layer.msg("修改失败: " + res.msg);
                                return false;
                            }
                        },
                        //请求的页面响应失败，则进行处理：
                        error:function (data) {
                            layer.msg(JSON.stringify(data.field),function(){
                                location.reload();
                            });
                            return false;
                        }
                    });
                    return false;
                });
            });
        </script>
    </body>
</html>